package com.seavenois.alife2;

public class Soul {

	private int duration; 					//Number of years the soul must be punished/rewarded
	private int stay = 0; 					//Number of years the soul has been punished/rewarded
	private byte color; 					//Sin/Virtue the soul must be punished/rewarded for
	private byte destiny; 					//Will the soul be reincarnated or trained
	private int train = 0; 					//Number of years the soul has been trained
	private boolean worker = false;			//Is the soul a trained worker already?
	private boolean reincarnation = false;	//Is the soul reincarnating THIS YEAR?
	
	Soul(){
		if (10 * Math.random() < Values.REINCARNATION_RATE)
		        destiny = Values.REINCARNATION;
		else
		        destiny = Values.INSTRUCTION;
		duration = (int) ((Math.random() * 80) + 20);
		color = (byte)(Math.random() * 7 + 1);
	}
	
	public void newYear(){
		//If the soul is still in its reward/punish area
		if(stay < duration)
			stay++;
		//Is the soul still looking for to some reward/punish area?
		if(stay == duration)
			color = Values.COLOR_NONE;
		//Should the soul reincarnate now?
		if(stay == duration && destiny == Values.REINCARNATION)
			reincarnation = true;
		//If the soul is being trained
		if(stay == duration && destiny == Values.INSTRUCTION);
			train++;
		//The soul has graduated?
		if(train >= Values.TRAINING_DURATION)
			worker = true;
	}
	
	public boolean isReincarnating(){
		return reincarnation;
	}
	
	public boolean isWorker(){
		return worker;
	}
	
	public byte getColor() {
		return color;
	}
	
	public boolean isTraining(){
		if(train >= 0 && stay >= duration)
		        return true;
		else
		        return false;
	}
}
